package com.shujia.wyh.day18;

import java.util.ArrayList;
import java.util.Collection;

/*
        向Collection集合中添加学生对象并遍历使用
 */
public class CollectionDemo4 {
    public static void main(String[] args) {
        //创建集合对象
        Collection c1 = new ArrayList();

        //创建学生对象
        Student s1 = new Student("沸羊羊", 18);
        Student s2 = new Student("黑小虎", 16);
        Student s3 = new Student("双面龟", 19);

        //将学生对象添加到集合中
        c1.add(s1);
        c1.add(s2);
        c1.add(s3);

        //遍历集合得到每一个学生对象
        //将集合转成数组
        Object[] objects = c1.toArray();

        //遍历数组
        for (int i = 0; i < objects.length; i++) {
//            System.out.println(objects[i]);
            Student student = (Student) objects[i];
            System.out.println(student.getName() + "---" + student.getAge());
        }
    }
}
